from django.db import models

# Create your models here.
from datetime import datetime, timezone, timedelta


class UserInfo(models.Model):
    """三个字段用户名，密码和令牌，其中设定token可以为空"""

    id = models.AutoField(primary_key=True)
    email = models.EmailField(max_length=64, null=True, blank=True, help_text="邮箱名")
    username = models.CharField(max_length=64, null=True, blank=True, help_text="用户名")
    password = models.CharField(max_length=64, null=True, blank=True, help_text="密码")
    role_name = models.CharField(max_length=64, null=True, blank=True, help_text="角色")
    mobile = models.CharField(max_length=64, null=True, blank=True, help_text="手机号")
    mg_state = models.BooleanField(null=True, blank=True, help_text="用户状态")
    create_time = models.DateTimeField(null=True, blank=True, help_text="创建时间")
    update_time = models.DateTimeField(null=True, blank=True, help_text="更新时间")

    # def save(self, *args, **kwargs):
    #     ''' On save, update timestamps '''
    #     if not self.id:
    #         self.created = timezone.now()
    #     self.modified = timezone.now()
    #     return super(UserInfo, self).save(*args, **kwargs)


    # 模型类中设置:blank=True,表示代码中创建数据库记录时该字段可传空白(空串,空字符串)
    # token = models.CharField(max_length=64, null=True, blank=True)


class Menu(models.Model):
    primary_directory_id = models.CharField(max_length=256, null=True, blank=True)  # 一级目录id
    primary_directory_path = models.CharField(max_length=256, null=True, blank=True)  # 一级目录路径
    primary_directory_name = models.CharField(max_length=256, null=True, blank=True)  # 一级目录名称


class ChildrenMenu(models.Model):
    secondary_directory_id = models.CharField(max_length=256, null=True, blank=True)  # 二级级目录id
    secondary_directory_path = models.CharField(max_length=256, null=True, blank=True)  # 二级目录路径
    secondary_directory_name = models.CharField(max_length=256, null=True, blank=True)  # 二级目录名称
    menu_ChildrenMenu_id = models.CharField(max_length=256, null=True, blank=True)  # 关联一级目录


class UserAuthList(models.Model):
    """
    用户角色表
    """
    role_name = models.CharField(max_length=256, null=True, blank=True)
    function_authority = models.CharField(max_length=256, null=True, blank=True)
    user_auth_id = models.CharField(max_length=256, null=True, blank=True)


class UserAuth(models.Model):
    """
    用户权限表
    """
    function_authority = models.CharField(max_length=256, null=True, blank=True)


class EnvironmentList(models.Model):
    """
    环境信息表
    """
    agreement = models.CharField(max_length=256, null=True, blank=True)  # 协议
    domain_name = models.CharField(max_length=256, null=True, blank=True)  # 域名
    port = models.CharField(max_length=256, null=True, blank=True)  # 端口
    info = models.CharField(max_length=256, null=True, blank=True)  # 描述信息
    remark = models.CharField(max_length=256, null=True, blank=True)  # 备注



# class Person(models.Model):
#     username = models.CharField(max_length=30)
#     password = models.CharField(max_length=256)
#
#     class Meta:
#         db_table = 'person'



